package com.jse.io.nio.network.old;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.log4j.Logger;

public class StreamUtil {
	public static final Logger mylog = Logger.getLogger(StreamUtil.class);
	
	public static String getInput(InputStream input) {
		int count = 1024;

		if (input != null) {
			try {
				// while (count == 0) {
				// count = input.available();
				// }
				byte[] buffer = new byte[count];
				input.read(buffer);
//				input
				// input.close();
				return new String(buffer).toString();
			} catch (Exception e) {
				mylog.error("读取文件流发生错误");
			}
		}

		return null;
	}
	
	public static String getReaderString(InputStream input) throws Exception {
		BufferedReader buffer = new BufferedReader(new InputStreamReader(input));
		String userInput = null;
		while((userInput = buffer.readLine()) != null) {
			System.out.println(userInput);
//			userInput += userInput;
		}
		
		return userInput;
	}
}
